import IconFont from '@/components/IconFont'
import styles from './index.module.less'
import { navList } from './const'
import classNames from 'classnames'
import png_peixunbaoming from '@/assets/common/home/png_peixunbaoming@2x.png'
import png_aiqiuzhi from '@/assets/common/home/png_aiqiuzhi@2x.png'
import HeaderTitle from './components/HeaderTitle'
import AiSeekEmploymentContent from './components/AiSeekEmploymentContent'
import EmploymentActiveContent from './components/EmploymentActiveContent'
import PositionZone from './components/PositionZone'
import TrainingRegistration from './components/TrainingRegistration'
import JobEvaluation from './components/JobEvaluation'
import ExcellentLecturer from './components/ExcellentLecturer'
import StudentVoices from './components/StudentVoices'
import FooterBar from './components/FooterBar'
import { history, useRequest } from 'umi'
import { getEnroll, getHome, getBanner, getTeachers, getStudents, getEval, getSign, getSiteInfo } from './api'
import { Swiper } from 'antd-mobile'
import { getLocalStorage } from '@/storage'

/**   求职实训1.45-就业援助接 首页 */
const Workbench = () => {
    const { data: signData } = useRequest(getEnroll, {
        defaultParams: [{ page: 1, per_page: 2 }],
    })

    const { data: homeData } = useRequest(getHome)

    const { data: bannerData } = useRequest(getBanner, {
        defaultParams: [{ adapter: 3 }],
    })
    const { data: teachersData } = useRequest(getTeachers, {
        defaultParams: [{ page: 1, per_page: 2 }],
    })

    const { data: studentsData } = useRequest(getStudents, {
        defaultParams: [{ page: 1, per_page: 2 }],
    })

    const { data: evalData } = useRequest(getEval)

    const { data: siteInfo } = useRequest(getSiteInfo)
    const { website_region, website, website_subtitle, logo, plantform_site_config } = siteInfo?.data || {}
    const { configList = [] } = plantform_site_config || {}
    const midMobileDomain = configList?.filter((it: any) => it.key === 'midMobileDomain')?.[0]?.value || ''

    const items = bannerData?.data?.list.map((item: any) => (
        <Swiper.Item key={item.id}>
            <img src={item.img_url} alt="" />
        </Swiper.Item>
    ))

    const { data: configData } = useRequest(getSign, {
        defaultParams: [getLocalStorage('CHOOSE_PLATFORM_SITE')],
    })

    return (
        <>
            <div className={styles.workbench_page}>
                <div className={styles.sid_header}>
                    <img src={logo} alt="" />
                    <span>
                        {website_region}
                        {website}
                        {website_subtitle}
                    </span>
                    <IconFont
                        type="icon-qiehuan"
                        className={styles.qiehuan_icon}
                        onClick={() => {
                            history.push('/workbench/chooseAPlatform')
                        }}
                    />
                </div>
                <div
                    onClick={() => {
                        window.location.href = configData?.data?.url_link
                    }}
                >
                    <div className={styles.cover}>
                        <Swiper autoplay loop className={styles.swiper_box}>
                            {items}
                        </Swiper>
                    </div>
                    <div className={styles.home_nav}>
                        {navList().map(i => {
                            return (
                                <div key={i.name} className={classNames(styles.nav_item, styles.student_nav)}>
                                    <img src={i?.url} alt="" />
                                    <div>{i.name}</div>
                                </div>
                            )
                        })}
                    </div>

                    {/* 培训报名 */}
                    <div className={styles.training}>
                        <HeaderTitle title="培训报名" />
                        <div className={styles.training_cover}>
                            <img src={png_peixunbaoming} alt="" />
                        </div>
                        <TrainingRegistration list={signData?.data?.list} />
                    </div>

                    {/* AI求职 */}
                    <div className={styles.ai_seekEmployment}>
                        <HeaderTitle title="AI求职" />
                        <div className={styles.ai_seekEmployment_cover}>
                            <img src={png_aiqiuzhi} alt="" />
                        </div>
                        <AiSeekEmploymentContent />
                    </div>

                    {/* 就业活动 */}
                    {homeData?.data?.activity_list.length > 0 && (
                        <div className={styles.employmentActivities}>
                            <HeaderTitle title="就业活动" />
                            <EmploymentActiveContent list={homeData?.data?.activity_list} />
                        </div>
                    )}

                    {/* 职位专区 */}
                    {homeData?.data?.profession_list?.new_list.length > 0 && (
                        <div className={styles.positionZone}>
                            <HeaderTitle title="职位专区" />
                            <PositionZone list={homeData?.data?.profession_list?.new_list} />
                        </div>
                    )}

                    {/* 求职测评 */}
                    <div className={styles.jobEvaluation}>
                        <HeaderTitle title="求职测评" />
                        <JobEvaluation list={evalData?.data} />
                    </div>

                    {/* 优秀讲师 */}
                    {teachersData?.data?.list.length > 0 && (
                        <div className={styles.excellentLecturer}>
                            <HeaderTitle title="优秀讲师" />
                            <ExcellentLecturer list={teachersData?.data?.list} />
                        </div>
                    )}

                    {/* 学员心声 */}
                    {studentsData?.data?.list.length > 0 && (
                        <div className={styles.studentVoices}>
                            <HeaderTitle title="学员心声" />
                            <StudentVoices list={studentsData?.data?.list} />
                        </div>
                    )}
                </div>
            </div>
            <FooterBar url={midMobileDomain} />
        </>
    )
}

export default Workbench
